/* 
 * File:   Box2dParallelJoint.cpp
 * Author: Elevator
 * 
 * Created on 27 Май 2013 г., 19:59
 */

#include "Box2dParallelJoint.h"
#include <Box2D/Box2D.h>

namespace physics {

	Box2dParallelJoint::Box2dParallelJoint(
		Box2dBody* bodyA, Box2dBody* bodyB,
		b2PrismaticJoint* joint )
	:
	_bodyA( bodyA ),
	_bodyB( bodyB ),
	_joint( joint ) {
	}

	Box2dParallelJoint::~Box2dParallelJoint( ) {
	}

	IBody* Box2dParallelJoint::GetBodyA( ) const {
		return _bodyA;
	}

	IBody* Box2dParallelJoint::GetBodyB( ) const {
		return _bodyB;
	}

	Vec2 Box2dParallelJoint::GetAnchorA( ) const {
		b2Vec2 anchor = _joint->GetAnchorB( );
		return Vec2( anchor.x, anchor.y );
	}

	Vec2 Box2dParallelJoint::GetAnchorB( ) const {
		b2Vec2 anchor = _joint->GetAnchorB( );
		return Vec2( anchor.x, anchor.y );
	}

	Vec2 Box2dParallelJoint::GetAxis( ) const {
		return ( GetAnchorB( ) - GetAnchorA( ) ).Normalize( );
	}

	bool Box2dParallelJoint::IsLimitEnabled( ) const {
		return _joint->IsLimitEnabled( );
	}

	void Box2dParallelJoint::SetLimitEnabled( bool enableLimit ) {
		_joint->EnableLimit( enableLimit );
	}

	float Box2dParallelJoint::GetLeftLimit( ) const {
		return _joint->GetUpperLimit( );
	}

	void Box2dParallelJoint::SetLeftLimit( float leftLimit ) {
		float rightLimit = _joint->GetLowerLimit( );
		_joint->SetLimits( rightLimit, leftLimit );
	}

	float Box2dParallelJoint::GetRightLeftLimit( ) const {
		return _joint->GetLowerLimit( );
	}

	void Box2dParallelJoint::SetRightLimit( float rightLimit ) {
		float leftLimit = _joint->GetUpperLimit( );
		_joint->SetLimits( rightLimit, leftLimit );
	}

	bool Box2dParallelJoint::IsMotorEnabled( ) const {
		return _joint->IsMotorEnabled( );
	}

	void Box2dParallelJoint::SetMotorEnabled( bool enableMotor ) {
		_joint->EnableMotor( enableMotor );
	}

	float Box2dParallelJoint::GetMotorForce( ) const {
		return _joint->GetMotorForce( );
	}

	void Box2dParallelJoint::SetMotorForce( float force ) {
		_joint->SetMaxMotorForce( force );
	}

	float Box2dParallelJoint::GetMotorSpeed( ) const {
		return _joint->GetMotorSpeed( );
	}

	void Box2dParallelJoint::SetMotorSpeed( float speed ) {
		_joint->SetMotorSpeed( speed );
	}

	b2PrismaticJoint* Box2dParallelJoint::GetBox2dJoint( ) {
		return _joint;
	}
}
